﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace Hong.viewmodels
{
    public partial class MainViewModel: ObservableObject
    {
        private bool _isruning = true;
        public MainViewModel()
        {
            Task.Run(async () =>
            {
                while (_isruning)
                {
                    await Task.Delay(1000);
                    //Application.Current.Dispatcher.Invoke(() => {
                        dateString = DateTime.Now.ToString("yyyy-MM-dd H:mm:ss");
                    //});
                }
            });
        }

        [RelayCommand]
        private void myClose(Window win)
        { 
            _isruning = false;
            win.Close();
        }

        [RelayCommand]
        private void myMin(Window win)
        {
            win.WindowState = WindowState.Minimized;
        }
        [RelayCommand]
        private void myMax(Window win)
        {
            if (win.WindowState == WindowState.Maximized)
            {
                win.WindowState = WindowState.Normal;
            }
            else
            {
                win.WindowState = WindowState.Maximized;
            }
        }
        private string _dateString = DateTime.Now.ToString("yyyy-MM-dd H:mm:ss");

        public string dateString
        {
            get { return _dateString; }
            set { SetProperty(ref _dateString, value); }
        }

    }
}
